package com.sykj.manage.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.BisOpinionService;
import com.sykj.manage.model.BisOpinion;
import com.sykj.manage.model.BisShop;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;

/**
 * 意见管理控制层
 * @author 蔡聪
 *	2018年9月28日下午2:52:14
 */
@Controller
@RequestMapping("/bisopinion")
public class BisOpinionController {
	@Autowired
	BisOpinionService bisOpinionService;
	
	/**
	 * 显示意见内容的实现方法
	 * @param bisShop
	 * @param offset
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/")
	@ResponseBody
	public ManageBody bisopinion(BisOpinion bisOpinion,Integer offset,Integer pageSize){
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		System.out.println(bisOpinion);
		List<BisOpinion> allBisOpinion = bisOpinionService.allBisOpinion(bisOpinion);
		PageInfo<BisOpinion>pageInfo=new PageInfo<BisOpinion>(allBisOpinion);
		return ManageBody.getData((int)pageInfo.getTotal(),pageInfo.getList(),"");
		/*return ManageBody.getData(1, allBisOpinion, "");*/
	}
	
	/**
	 * 根据id来删除意见信息
	 * @param opinion_id
	 * @return
	 */
	@RequestMapping("/del/{opinion_id}")
	@ResponseBody
	public ManageBody del(@PathVariable("opinion_id")String opinion_id){
		 int deleteBisOpinion = bisOpinionService.deleteBisOpinion(opinion_id);
		if (deleteBisOpinion>0) {
			return ManageBody.getData(1, deleteBisOpinion, "");
		}else {
			return ManageBody.getData(1, deleteBisOpinion, "");
		}
		
		
	}
	
	/**
	 * 根据id来查一条数据
	 * @param opinion_id
	 * @return
	 */
	@RequestMapping("/seleBisopin")
	@ResponseBody
	public Object seleBisopin(String opinion_id){
		
		BisOpinion seleBisopinion = bisOpinionService.seleBisopinion(opinion_id);
		return seleBisopinion;
	}
}
